home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Basic / Visual Basic.60 / COMMON / TOOLS / VCM / VCM.MDB / VcmComponentContainer / 14_Cabinet / ERRORDLG.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1998-05-18  |  3.8 KB  |  149 lines

  1. // ErrorDlg.cpp : implementation file
  2. //
  3. // This is a part of the Microsoft Foundation Classes and
  4. // Templates (MFC&T).
  5. // Copyright (C) 1998 Microsoft Corporation
  6. // All rights reserved.
  7. //
  8. // This source code is only intended as a supplement to the
  9. // MFC&T Reference and related electronic documentation provided
  10. // with the library.  See these sources for detailed information
  11. // regarding the MFC&T product.
  12. //
  13.  
  14. #include "stdafx.h"
  15. #include "dbviewer.h"
  16. #include "ErrorDlg.h"
  17.  
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CErrorsDialog dialog
  26.  
  27.  
  28. CErrorsDialog::CErrorsDialog(CWnd* pParent /*=NULL*/)
  29.     : CDialog(CErrorsDialog::IDD, pParent)
  30. {
  31.     //{{AFX_DATA_INIT(CErrorsDialog)
  32.     //}}AFX_DATA_INIT
  33.     m_nSelectedItem = -1;
  34. }
  35.  
  36.  
  37. void CErrorsDialog::DoDataExchange(CDataExchange* pDX)
  38. {
  39.     CDialog::DoDataExchange(pDX);
  40.     //{{AFX_DATA_MAP(CErrorsDialog)
  41.     DDX_Control(pDX, IDC_EDIT_GUID, m_ctlGUID);
  42.     DDX_Control(pDX, IDC_LIST_SOURCE, m_ctlListSource);
  43.     DDX_Control(pDX, IDC_EDIT_DESCRIPTION, m_ctlDescription);
  44.     DDX_Control(pDX, IDHELP, m_ctlHelp);
  45.     //}}AFX_DATA_MAP
  46. }
  47.  
  48. BEGIN_MESSAGE_MAP(CErrorsDialog, CDialog)
  49.     //{{AFX_MSG_MAP(CErrorsDialog)
  50.     ON_BN_CLICKED(IDHELP, OnHelp)
  51.     ON_LBN_SELCHANGE(IDC_LIST_SOURCE, OnSelChange)
  52.     //}}AFX_MSG_MAP
  53. END_MESSAGE_MAP()
  54.  
  55. /////////////////////////////////////////////////////////////////////////////
  56. // CErrorsDialog message handlers
  57.  
  58. BOOL CErrorsDialog::OnInitDialog()
  59. {
  60.     USES_CONVERSION;
  61.     CDialog::OnInitDialog();
  62.  
  63.     // Set the help button to be inactive
  64.     m_ctlHelp.EnableWindow(FALSE);
  65.  
  66.     // Read in the error information from IErrorRecords
  67.     CDBErrorInfo errInfo;
  68.     ULONG ulRecords = 0;
  69.     HRESULT hr;
  70.  
  71.     hr = errInfo.GetErrorRecords(m_spUnk, m_iid, &ulRecords);
  72.     if (FAILED(hr) || hr == S_FALSE || ulRecords == 0)
  73.     {
  74.         CString strError;
  75.         strError.LoadString(IDS_NOSPECIFIED_SOURCE);
  76.         m_ctlListSource.AddString(strError);
  77.     }
  78.     else
  79.     {
  80.         LCID lcid = GetUserDefaultLCID();
  81.         for (ULONG l=0; l<ulRecords; l++)
  82.         {
  83.             // Get the error information from the source
  84.             struct MYERRORINFO* pInfo = new MYERRORINFO;
  85.             hr = errInfo.GetAllErrorInfo(l, lcid, &pInfo->bstrDescription,
  86.                 &pInfo->bstrSource, &pInfo->guid, &pInfo->dwHelpContext,
  87.                 &pInfo->bstrHelpFile);
  88.             if (FAILED(hr))
  89.             {
  90.                 delete pInfo;
  91.                 continue;
  92.             }
  93.  
  94.             m_listErrorInfo.AddTail(pInfo);
  95.  
  96.             // Add the information to the list view
  97.             m_ctlListSource.AddString(OLE2T(pInfo->bstrSource));
  98.         }
  99.     }
  100.     m_ctlListSource.SetCurSel(0);
  101.     SelectSource(0);
  102.     return TRUE;  // return TRUE unless you set the focus to a control
  103.                   // EXCEPTION: OCX Property Pages should return FALSE
  104. }
  105.  
  106. void CErrorsDialog::OnHelp()
  107. {
  108.     USES_CONVERSION;
  109.  
  110.     if (m_nSelectedItem != -1)
  111.     {
  112.         POSITION pos = m_listErrorInfo.FindIndex(m_nSelectedItem);
  113.         struct MYERRORINFO* pInfo = (MYERRORINFO*)m_listErrorInfo.GetAt(pos);
  114.  
  115.         // Call WinHelp
  116.         ::WinHelp(GetSafeHwnd(), OLE2T(pInfo->bstrHelpFile), HELP_CONTEXT,
  117.             pInfo->dwHelpContext);
  118.     }
  119. }
  120.  
  121. void CErrorsDialog::OnSelChange()
  122. {
  123.     m_nSelectedItem = m_ctlListSource.GetCurSel();
  124.     SelectSource(m_nSelectedItem);
  125. }
  126.  
  127. void CErrorsDialog::SelectSource(int nSel)
  128. {
  129.     USES_CONVERSION;
  130.  
  131.     if (m_listErrorInfo.IsEmpty())
  132.     {
  133.         CString strError;
  134.         strError.LoadString(IDS_NOSPECIFIED_ERROR);
  135.         m_ctlDescription.SetWindowText(strError);
  136.         m_ctlGUID.SetWindowText(_T(""));
  137.     }
  138.     else
  139.     {
  140.         OLECHAR szGUID[40];
  141.         POSITION pos = m_listErrorInfo.FindIndex(nSel);
  142.         struct MYERRORINFO* pInfo = (MYERRORINFO*)m_listErrorInfo.GetAt(pos);
  143.  
  144.         m_ctlDescription.SetWindowText(OLE2T(pInfo->bstrDescription));
  145.         ::StringFromGUID2(pInfo->guid, szGUID, 40);
  146.         m_ctlGUID.SetWindowText(OLE2T(szGUID));
  147.     }
  148. }
  149.